﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using Customer_Profile.eCard.DBDao;
using KVB.Common;
using Customer_Profile.Admin;

namespace Customer_Profile.eCard
{
    public partial class CpartyAdd : System.Web.UI.Page
    {
        string strUserName = "";
        string strUserID = "";
        string strEntity = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            Comm.CheckSession(this.Page, "/login.aspx", "usermodel");
            if (Session["usermodel"] != null)
            {
                strUserID = ((UserInfoEntity)Session["usermodel"]).UserLoginId;
                strUserName = ((UserInfoEntity)Session["usermodel"]).UserName;
                strEntity = ((UserInfoEntity)Session["usermodel"]).UserOffice;
            }
            else
            {
                Log.WriteDefaultLog("main_01 Page_Load", "Session is null");
                return;
            }

            if (!Page.IsPostBack)
            {
                Comm.BindDll(ref dropIDtype, "IDType", false, "");
            }
        }

        protected void btnCpartySave_Click(object sender, EventArgs e)
        {
            try
            {
                string cparty_name = txtName.Value;
                string phone = txtPhone.Value;
                string id_type = dropIDtype.SelectedItem.Value;
                string id_no = txtIDcode.Value;
                string sex = dropSex.SelectedItem.Value;
                string birthday = txtBirthday.Value;
                string email = txtEmail.Value;
                string zipcode = txtZip.Value;
                string address = txtAddress.Value;
                string entity = strEntity;  //dropEntity.SelectedItem.Value;
                string cparty_no = CpartyDao.AddCparty(cparty_name, entity, phone, id_type, id_no, sex, birthday, email, zipcode, address);
                if (!cparty_no.Equals(""))
                {                    
                    Response.Write("<script language=javascript>alert('success');</script>");
                }
                else
                {
                    Response.Write("<script language=javascript>alert('error');</script>");
                }
            }
            catch (Exception ex)
            {
                Log.WriteDefaultLog("btnCpartySave_Click", ex.ToString());
                Response.Write("<script language=javascript>alert('Error!');</script>");
            }
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("cpartySearch.aspx");
        }
    }
}